package com.qzsoft.zhjd.server.modules.asphalt.handler;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Set;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;

import com.qzsoft.zhjd.server.modules.asphalt.entity.CollectAsphaltDataRatioEntity;
import com.qzsoft.zhjd.server.modules.asphalt.entity.CollectAsphaltDataSieveEntity;
import com.qzsoft.zhjd.server.modules.asphalt.entity.CollectAsphaltDataWeightEntity;
import com.qzsoft.zhjd.server.modules.asphalt.entity.CollectAsphaltMatchHotEntity;

/**
 * @ClassName AsphaltDataSieveHandler
 * @Description 生产数据筛孔表处理
 * @author linhuawei
 * @since 2022-02-09
 */
public class AsphaltDataSieveHandler {

    /**
     * @Title coverTo
     * @Description 生产数据筛孔表处理
     * @param weightData 重量数据
     * @param ratioData  占比数据
     * @param hots       热料配置
     * @param sieveSet   筛孔
     * @return 生产数据筛孔表数据
     */
    public static CollectAsphaltDataSieveEntity coverTo(CollectAsphaltDataWeightEntity weightData, CollectAsphaltDataRatioEntity ratioData,
                                                        List<CollectAsphaltMatchHotEntity> hots, Set<String> sieveSet) {
        CollectAsphaltDataSieveEntity sieveData = new CollectAsphaltDataSieveEntity();
        BigDecimal value;
        BigDecimal hundred = new BigDecimal(100);
        String sieveSizeStr;
        if (ObjectUtils.isNotEmpty(hots) && null != sieveSet) {
            for (CollectAsphaltMatchHotEntity hot : hots) {
                // 当前筛孔不在级配筛孔中，不做处理
                sieveSizeStr = hot.getSieveSize().stripTrailingZeros().toPlainString();
                if (!sieveSet.contains(sieveSizeStr)) {
                    continue;
                }

                // 获取生产数据筛孔数据
                value = BigDecimal.ZERO;
                if (null != hot.getGravel1() && null != ratioData.getGravel1RatioW()) {
                    value = value.add(hot.getGravel1().multiply(ratioData.getGravel1RatioW()));
                }
                if (null != hot.getGravel2() && null != ratioData.getGravel2RatioW()) {
                    value = value.add(hot.getGravel2().multiply(ratioData.getGravel2RatioW()));
                }
                if (null != hot.getGravel3() && null != ratioData.getGravel3RatioW()) {
                    value = value.add(hot.getGravel3().multiply(ratioData.getGravel3RatioW()));
                }
                if (null != hot.getGravel4() && null != ratioData.getGravel4RatioW()) {
                    value = value.add(hot.getGravel4().multiply(ratioData.getGravel4RatioW()));
                }
                if (null != hot.getGravel5() && null != ratioData.getGravel5RatioW()) {
                    value = value.add(hot.getGravel5().multiply(ratioData.getGravel5RatioW()));
                }
                if (null != hot.getGravel6() && null != ratioData.getGravel6RatioW()) {
                    value = value.add(hot.getGravel6().multiply(ratioData.getGravel6RatioW()));
                }
                if (null != hot.getPowder1() && null != ratioData.getPowder1RatioW()) {
                    value = value.add(hot.getPowder1().multiply(ratioData.getPowder1RatioW()));
                }
                if (null != hot.getPowder2() && null != ratioData.getPowder2RatioW()) {
                    value = value.add(hot.getPowder2().multiply(ratioData.getPowder2RatioW()));
                }
                if (null != hot.getPowder3() && null != ratioData.getPowder3RatioW()) {
                    value = value.add(hot.getPowder3().multiply(ratioData.getPowder3RatioW()));
                }
                if (null != hot.getRecycledMaterial() && null != ratioData.getRecycledMaterialRatioW()) {
                    value = value.add(hot.getRecycledMaterial().multiply(ratioData.getRecycledMaterialRatioW()));
                }
                // 因为四舍五入的原因，可能出现超过100的情况，如果超过100设置为100
                value = value.divide(hundred, 2, RoundingMode.HALF_UP);
                if (1 == value.compareTo(hundred)) {
                    value = new BigDecimal(100);
                }

                if ("0.075".equals(sieveSizeStr)) {
                    sieveData.setSieve0d075(value);
                } else if ("0.15".equals(sieveSizeStr)) {
                    sieveData.setSieve0d15(value);
                } else if ("0.3".equals(sieveSizeStr)) {
                    sieveData.setSieve0d3(value);
                } else if ("0.6".equals(sieveSizeStr)) {
                    sieveData.setSieve0d6(value);
                } else if ("1.18".equals(sieveSizeStr)) {
                    sieveData.setSieve1d18(value);
                } else if ("2.36".equals(sieveSizeStr)) {
                    sieveData.setSieve2d36(value);
                } else if ("4.75".equals(sieveSizeStr)) {
                    sieveData.setSieve4d75(value);
                } else if ("9.5".equals(sieveSizeStr)) {
                    sieveData.setSieve9d5(value);
                } else if ("13.2".equals(sieveSizeStr)) {
                    sieveData.setSieve13d2(value);
                } else if ("16".equals(sieveSizeStr)) {
                    sieveData.setSieve16(value);
                } else if ("19".equals(sieveSizeStr)) {
                    sieveData.setSieve19(value);
                } else if ("26.5".equals(sieveSizeStr)) {
                    sieveData.setSieve26d5(value);
                } else if ("31.5".equals(sieveSizeStr)) {
                    sieveData.setSieve31d5(value);
                } else if ("37.5".equals(sieveSizeStr)) {
                    sieveData.setSieve37d5(value);
                } else if ("52".equals(sieveSizeStr)) {
                    sieveData.setSieve52(value);
                } else if ("53".equals(sieveSizeStr)) {
                    sieveData.setSieve53(value);
                }
            }
        }
        return sieveData;
    }

}
